package study.dadazuche;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;

public class DaDaApplication {
    public static void main(String[] args) {
        System.out.println("欢迎来到达达租车系统");
        System.out.println("请问您是要租车吗，租车输入1；退出输入0");
        Scanner input = new Scanner(System.in); //初始化Scanner；
        while(true) {
            int start = input.nextInt();  //获取用户输入
            if (start == 1) {
                System.out.println("您可以选择的租车列表如下：");
                Car[] cars = {   //创建父类数组
                        new Bus("奥迪A4L", 500, 5, 0),
                        new Truck("松花江", 400, 0, 5),
                        new Bus("马自达6", 400, 4, 0),
                        new Truck("依维柯", 1000, 0, 20),
                        new Bus("五菱宏光", 200, 30, 0),
                        new ManTruck("皮卡雪6", 450, 4, 2)
                };
                for (int i = 0; i < cars.length; i++) {   //循环列出数组内容
                    int number = i + 1;
                    System.out.print(number);
                    if (cars[i] instanceof Bus) {    //判断归属
                        System.out.println("载人车辆型号：" + cars[i].name + "，一天租金是" + cars[i].price + "块，载人量为" + cars[i].guest + "人，载货量为" + cars[i].goods + "吨");
                    } else if (cars[i] instanceof Truck) {
                        System.out.println("载货车辆型号：" + cars[i].name + "，一天租金是" + cars[i].price + "块，载人量为" + cars[i].guest + "人，载货量为" + cars[i].goods + "吨");
                    } else if (cars[i] instanceof ManTruck) {
                        System.out.println("载人载货车辆型号：" + cars[i].name + "，一天租金是" + cars[i].price + "块，载人量为" + cars[i].guest + "人，载货量为" + cars[i].goods + "吨");
                    }
                }
                System.out.print("请输入您需要的车辆数量：");
                int carNumber = input.nextInt();
                double totalPrice = 0;  //初始化租车总费用
                int totalGuest = 0;   //初始化租车总载人数
                double totalGoods = 0;   //初始化租车总载货量
                Car[] chooseCars = new Car[carNumber];   //创建车辆信息数组
                String[] carsName = new String[carNumber];   //获取租车车辆型号的数组
                for (int i = 0; i < carNumber; i++) {
                    int n = i + 1;
                    System.out.println("请输入第" + n + "辆车的序号：");
                    int chooseNumber = input.nextInt();
                    chooseCars[i] = cars[chooseNumber - 1];
                    totalPrice += chooseCars[i].price;
                    totalGuest += chooseCars[i].guest;
                    totalGoods += chooseCars[i].goods;
                    carsName[i] = chooseCars[i].name;
                }
                System.out.println("请输入您的租车天数：");
                int days = input.nextInt();
                totalPrice = totalPrice * days; //租车总金额=天数*租车金额
                System.out.println("选择完毕，下面将列出您的租车详情：");
                System.out.println("您的租车清单为：");
                System.out.println(Arrays.toString(carsName));
                System.out.println("载人总数为：" + totalGuest + "人");
                System.out.println("载货总数为：" + totalGoods + "吨");
                System.out.println("您的租车总费用为：" + totalPrice + "元");
            } else if (start == 0) {
                System.out.println("谢谢光临，期待您的下次光临");
            } else {   //输入错误的处理
                System.out.println("您输入的数字有误，请重新输入");
                continue;
            }
            break;
        }
    }
}
